package car.aistar.service.Impl.xrb;

import car.aistar.entity.CarRecord;
import car.aistar.service.CarRecordService;
import car.aistar.util.XrbUtil;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * @ClassName testUtil
 * @Description TODO 测试util工具类
 * @Author laoxu
 * @Date 2020/10/3 10:12
 * Version 1.0
 **/

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = "classpath:spring/spring-*.xml")
public class testUtil {
    @Autowired
    private CarRecordService carRecordService;

    @Test
    public void testGetDay(){
        String date = "2020-09-27 12:00:00";
        Long days = XrbUtil.getDay(date);
        System.out.println(days);
    }

    @Test
    public void testDateUtil(){
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        try {
            System.out.println(XrbUtil.StringToDate("1999-09-27 12:00:00"));
            System.out.println(XrbUtil.DateToString(new Date()));
            Date d = XrbUtil.getOneMonth();
            String day = format.format(d);
            System.out.println("前一个月"+day);
        } catch (ParseException e) {
            e.printStackTrace();
        }
    }

    @Test
    public void testNewRecord(){
        List<CarRecord> carRecords = carRecordService.findDate("2000-09-27 10:00:00","2020-09-27 10:00:00");
        for (CarRecord carRecord : carRecords) {
            System.out.println(carRecord.getId());
        }
    }
}
